/*
 * hello.c
 *
 *  Created on: 2015年6月26日
 *      Author: Administrator
 */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
#include <fcntl.h>
#include <pthread.h>
#include "log.h"
#include "hooksmssend.h"
#include "hookconnectivity.h"
#include <string.h>

using namespace android;

#ifdef __cplusplus
extern "C" {
#endif
int hook_entry(char *);
#ifdef __cplusplus
}
#endif

void * _main(void *param)
{
    char *cla = (char *)param;
    LOGI("%s", (char *)param);
    if(strstr(cla, "com.android.phone")){
        HookEntry *hookobj = HookSMSSend::GetInstance();
        hookobj->hook();
    }
    if(strstr(cla, "system_server")){
        HookEntry *hookobj = HookConnectivity::GetInstance();
        hookobj->hook();
    }
    LOGI("main is finished!!");
    return NULL;
}

int hook_entry(char * param){

    pthread_t tid;
    pthread_create(&tid, NULL, _main, param);
    pthread_detach(tid);
}

#if 0
//void breforemain() __attribute__((constructor));
__attribute__((constructor))
void breforemain()
{
    LOGD("my auto exec test\n");
}

//////////////////////////////////
void Main()
{
    LOGD("enter Main\n");
}

static void* _main(void*){
    Main();
    return NULL;
}

class EntryClass {
public:

    EntryClass() {
        pthread_t tid;
        pthread_create(&tid, NULL, _main, NULL);
        pthread_detach(tid);
    }

} boy;
#endif
